﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using TVersityDotNet.HelperTypes;

namespace TVersityDotNet.Responses
{
    public class MediaSourceFetchResponse : TVersityResponse
    {
        public MediaSource MediaSource { get; set; }

        public MediaSourceFetchResponse(XDocument responseXmlDoc)
        {
            if (responseXmlDoc != null)
            {
                this.ParseMessage(responseXmlDoc);
                if (this.ResponseSuccess)
                {
                    MediaSourceFetchListResponse listResponse = new MediaSourceFetchListResponse(responseXmlDoc);
                    if (listResponse.ResponseSuccess && listResponse.ListOfSources.Count > 0)
                        this.MediaSource = listResponse.ListOfSources[0];
                    else
                        this.ResponseSuccess = false;
                }
            }
            else
            {
                this.ResponseSuccess = false;
                this.ResponseMessage = "Provided responseXml was null";
            }
        }
    }
}
